package lock.countDownLatch.hospital;

import java.util.concurrent.CountDownLatch;

/**
 * 挂号任务
 */
public class GuaHaoTask implements Runnable {

    private CountDownLatch countDownLatch;

    public GuaHaoTask(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    public void run() {
        System.out.println("开始排队挂号。。。");
        try {
            // 模拟耗时操作
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 任务执行完成后，锁的计数器减1
            countDownLatch.countDown();
            System.out.println("挂号完成后计数器为：" + countDownLatch.getCount());
        }
    }

}
